GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

elementContains.js ➔ elementContains   B
last analyzed

Complexity

Conditions 10
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
nc 4
dl 0
loc 17
rs 7.2765
c 0
b 0
f 0
nop 2

How to fix   Complexity   

Complexity

Complex classes like elementContains.js ➔ elementContains often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
export function elementContains(el, ...classes) {
2
3
    if (!el || !classes || !classes.length) {
4
        throw Error('Function requires a dom node and a classname');
5
    }
6
7
    while (el && el !== document.body) {
8
        if (el && el.classList) {
9
            for (let i = 0; i < classes.length; i++) {
10
                if (el.classList.contains(classes[i])) {
11
                    return true;
12
                }
13
            }
14
        }
15
        el = el.parentNode;
16
    }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
17
}